function [mx, my, sx, sy] = statanalyze( bitmap )
% [mx my sx sy] = statanalyze( bitmap ) - analizes 2D, bolean bitmap.
% Returns mean x,y nad std dev in both directions

% bitmap dimensions
w = size ( bitmap, 2 );
h = size ( bitmap ,1 );

% num of points in bitmap
points = sum( sum (bitmap ) );

% points position
xmatrix = ones( h, 1 ) * [ 1: w ];
ymatrix = [1:h]' * ones(1, w );

xs = xmatrix .* bitmap;
ys = ymatrix .* bitmap;

% convert coordinates to vectors (sorted descending)
xvector = fliplr( sort( reshape( xs, 1, w*h ) ) );
yvector = fliplr( sort( reshape( ys, 1, w*h ) ) );

% leave only meaningful data (remove zeros)
yv = yvector(1:points);
xv = xvector(1:points);

mx = mean(xv);
my = mean(yv);
sx = std(xv);
sy = std(yv);

